package redis

import (
	"context"
	"encoding/json"
	"log"

	"qmp_go_push/conf"

	"github.com/go-redis/redis/v8"
)

var redisClient *redis.Client

func InitRedis() {
	redisClient = redis.NewClient(&redis.Options{
		Addr:     conf.CONFIG.Redis.Host,
		Password: "",
		DB:       conf.CONFIG.Redis.DB,
	})

	if _, err := redisClient.Ping(context.Background()).Result(); err != nil {
		log.Fatal("Fatal error redisClient.Ping(): \n", err.Error())
	}

	log.Println("===============初始化Redis配置成功===============")
	marshalIndent, _ := json.MarshalIndent(&conf.CONFIG.Redis, "", "\t")
	log.Println(string(marshalIndent))
	log.Println()
	log.Println()
}
